<template>
  <div class="mod-config">
    <basic-container>
      <navigation :sign="{a:false,b:true,c:false,d:false,e:false}"></navigation>
      <div class="boxsty zhiBiao">
        <div class="flex justifyContentSpaceBetween">
          <div class="tabletext">奖金计算方法维护</div>
          <div class="tablelink">
            <el-link icon="el-icon-setting" v-if="permissions.jiangjin_jiangjinjjxxxb_add" type="primary"
                     :underline="false" :disabled="deptId===''" @click="configWin">设置计算方法
            </el-link>
          </div>
        </div>
        <div style="margin-top:20px;width:100%">
          <span><b>负责部门：{{ deptName }}</b></span>
        </div>
        <div class="avue-crud fenZuZu" style="max-height:calc(100vh - 370px)">
        <el-card class="box-card" style="margin-top: 30px; width:98%;" v-for="(t,i) in this.jjConfig" :key="i">
          <div slot="header" class="clearfix mainBoxCard">
            <span class="font18 blue"><b>{{ t.ryfzMc }}</b></span>
          </div>
          <el-row :gutter="20">
            <el-col :span="6" v-for="(r,j) in t.jjx" :key="i*1000+j" class="mb10">
              {{ r.jjxMc }}：{{ r.jjgs.gsMc }}
            </el-col>
          </el-row>
        </el-card>
        </div>
      </div>
    </basic-container>
    <form-win ref="formWin" @refreshDataList="getDataList"></form-win>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
import {getJiangJinBm} from '@/api/admin/dept'
import {getObj} from '@/api/jiangjin/jiangjinjjjsffb'
import formWin from './jiangjinjjjsffb-form'

export default {
  data() {
    return {
      deptId: '',//负责部门ID
      deptName: '',//负责部门名称
      config: false,
      configData: {},
      jjConfig: {}
    }
  },
  components: {
    formWin
  },
  created() {

  },
  mounted() {
    this.getJiangJinJg();
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    //获取奖金管理人机构
    getJiangJinJg() {
      getJiangJinBm().then(res => {
        if (res.data.data != null && res.data.data.length > 0) {
          this.deptId = "";
          this.deptName = "";
          this.deptId = res.data.data[0].deptId;
          this.deptName = res.data.data[0].name;
          this.getDataList();
        } else {
          this.$notify.closeAll();
          //this.$notify.error("没有相关负责部门")
          //this.deptName = "无相关负责部门";
        }
      });
    },
    getDataList() {
      getObj(this.deptId).then(res => {
        if (res.data.data) {
          this.config = true;
          this.configData = res.data.data;
          this.jjConfig = JSON.parse(res.data.data.jjConfig);
        } else {
          this.$notify.closeAll();
          this.$notify.error(this.deptName + "的奖金计算方法没有配置")
          this.config = false;
          this.configData = {};
        }
      })
    },
    configWin() {
      this.$refs.formWin.init(this.deptId)
    }
  }
}

</script>
